import json
import time

from config.driver_config import DriverConfig
from logs.log import get_log
from page.HomePage import HomePage
from page.LoginPage import LoginPage
from page.PrintBatchBusCardLoginPage import PrintBatchBusCardLoginPage
from page.PrintBusCardLoginPage import PrintBusCardLoginPage
from page.PrintLoginPage import PrintLoginPage
from page.TestPrintPage import TestPrintPage
from page.PrintRemitLoginPage import PrintRemitLoginPage

log = get_log("lanuch")


def print_click(data):
    log.info("打印测试开始")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    page = PrintLoginPage()
    page.to_login(driver, "https://59.255.67.8/#", "111111")
    data = page.to_print(driver, data)
    time.sleep(2)
    driver.close()
    return data


def bx_click(data):
    log.info("show child")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    for item in data:
        LoginPage().to_login(driver, "00011", "Nk123qwe!@#")
        time.sleep(0.2)
        home_page = HomePage()
        home_page.click_menu(driver, "报销管理")
        time.sleep(0.2)
        home_page.click_menu(driver, "我要报销")
        time.sleep(0.1)
        home_page.to_normal_bx(driver)
        item['success'] = True
        item['message'] = ''
    time.sleep(2)
    driver.close()
    return data


def wy_pay(data):
    log.info("wy_pay")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    page = PrintBusCardLoginPage()
    page.to_login(driver, "https://59.255.67.8/#", "111111")
    data = page.to_print(driver, data, "111111")
    time.sleep(3)
    driver.close()
    return data


def batch_wy_pay(data):
    log.info("batch_wy_pay")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    page = PrintBatchBusCardLoginPage()
    page.to_login(driver, "https://59.255.67.8/#", "111111")
    data = page.to_print(driver, data, "111111")
    time.sleep(3)
    driver.close()
    return data


def test_dy(data):
    log.info("test_dy")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    LoginPage().to_login(driver, "00011", "Nk123qwe!@#", "http://localhost:8080/login")
    time.sleep(0.2)
    page = TestPrintPage()
    page.click_menu(driver, "报销管理")
    time.sleep(0.2)
    page.click_menu(driver, "我的报销单")
    time.sleep(0.1)
    page.to_print(driver)
    time.sleep(3)
    driver.close()
    return data

def remit_pay(data):
    log.info("remit_pay")
    log.info(json.dumps(data))
    driver = DriverConfig().driver_config()
    page = PrintRemitLoginPage()
    page.to_login(driver, "https://59.255.67.8/#", "111111")
    data = page.to_print(driver, data, "111111")
    time.sleep(3)
    driver.close()
    return data
